<?php
/**
 * Created by 上海风车教育科技有限公司.
 * User: 刘红伟
 * Email: 454303753@qq.com
 * File:wechatuserinfo.php
 */
class  wechatuserinfo {
    private $url="https://api.weixin.qq.com/cgi-bin/user/info";
    private  $token;
    private  $openID;
    private  $lang='zh_CN';

    public function __construct($token,$openID='',$lang='')
    {
        $this->token=$token;
        $this->openID=$openID;

        if(!empty($lang)){
           $this->lang=$lang;
        }

    }

    private function _parseUrl()
    {
        return $this->url.'?access_token='.$this->token.'&openid='.$this->openID.'&lang='.$this->lang;
    }

    public function getUserInfo()
    {
        $url=$this->_parseUrl();

        $http= wx_http::factory($url,wx_http::TYPE_CURL);
        $json= $http->get();
        $result=json_decode($json,true);

        if(isset($result['errcode']) && $result['errcode']>0)
        {
            return false;

        }else{

            return $result;
        }
    }

}